package com.nsoft.thickclient.trackMove.party;

import java.awt.Color;
import java.awt.GridLayout;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;

import com.nsoft.thickclient.components.VoPropertyInputField;
import com.nsoft.thickclient.components.VoPropertyTextArea;
import com.nsoft.thickclient.components.date.VoPropertyDateField;
import com.nsoft.thickclient.containers.NBoxPanel;
import com.nsoft.thickclient.containers.NGridPanel;
import com.nsoft.thickclient.containers.VOPropertyComponentPanel;
import com.nsoft.thickclient.controller.ScreenView;
import com.nsoft.thickclient.model.VoModel;
import com.nsoft.thickclient.trackMove.intr.party.Party;

public class PartyView extends ScreenView<Party> {
	/**
	 * serialVersionUID = 1L.
	 */
	private static final long serialVersionUID = 1L;

	private VoModel model = new VoModel(Party.class);

	public PartyView(Party party) {
		if (party != null) {
			model.setValueObject(party);
		}
		NBoxPanel boxPanel = new NBoxPanel(NBoxPanel.VERTICAL);
		boxPanel.addComponent(getNamePanel());
		boxPanel.addComponent(getAddressPanel());
		boxPanel.addComponent(getPanPanel());
		boxPanel.addComponent(getNotesPanel());
		this.add(boxPanel);
	}

	private JComponent getNamePanel() {
		NGridPanel panel = new NGridPanel();
		panel.setBorder(BorderFactory.createTitledBorder("Contact details"));
		panel.addComponent("Name", new VoPropertyInputField(model, "name"), 0,
				0);
		VoPropertyDateField dateField = new VoPropertyDateField(model,
				"crteationDate");
		dateField.setDate(new Date());
		dateField.setEditable(false);
		dateField.setBackground(Color.WHITE);
		panel.addComponent("Creation date", dateField, 1, 0);
		panel.addComponent("Contact Person", new VoPropertyInputField(model,
				"contactPerson"), 0, 1);
		panel.addComponent("Contact phone number", new VoPropertyInputField(
				model, "contactPhone"), 1, 1);
		return panel;
	}

	private JComponent getAddressPanel() {
		JPanel mainPanel = new JPanel(new GridLayout(1, 2));
		mainPanel.setBorder(BorderFactory.createTitledBorder("Address"));
		VOPropertyComponentPanel officePanel = new VOPropertyComponentPanel();
		officePanel.setBorder(BorderFactory.createTitledBorder("Office"));
		officePanel.addVoTextField(model, "officePhone", "Phone number", true);
		VoPropertyTextArea textArea = new VoPropertyTextArea(model,
				"officeAddr");
		textArea.setRows(5);
		textArea.setColumns(20);
		officePanel.addComponent("Address", textArea);
		mainPanel.add(officePanel);

		VOPropertyComponentPanel homePanel = new VOPropertyComponentPanel();
		homePanel.setBorder(BorderFactory.createTitledBorder("Home"));
		homePanel.addVoTextField(model, "homePhone", "Phone number", true);
		textArea = new VoPropertyTextArea(model, "homeAddr");
		textArea.setRows(5);
		textArea.setColumns(20);
		homePanel.addComponent("Address", textArea);
		mainPanel.add(homePanel);
		return mainPanel;
	}

	private JComponent getPanPanel() {
		NGridPanel panel = new NGridPanel();
		panel.setBorder(BorderFactory.createTitledBorder("Pan details"));
		panel.addComponent("PAN", new VoPropertyInputField(model, "pan"), 0, 0);
		panel.addComponent("TAN", new VoPropertyInputField(model, "tan"), 1, 0);
		panel.addComponent("TIN", new VoPropertyInputField(model, "tin"), 2, 0);
		panel.addComponent("Exim", new VoPropertyInputField(model, "exim"), 3,
				0);
		return panel;
	}

	private JComponent getNotesPanel() {
		VOPropertyComponentPanel panel = new VOPropertyComponentPanel();
		panel.setBorder(BorderFactory.createTitledBorder("Remarks"));
		VoPropertyTextArea textArea = new VoPropertyTextArea(model, "remarks");
		textArea.setRows(5);
		textArea.setColumns(60);
		panel.addComponent(null, textArea);
		return panel;

	}

	public VoModel getModel() {
		return model;
	}

	public void setModel(VoModel model) {
		this.model = model;
	}

	public Party getWorkingBean() {
		return (Party) model.getValueObject();
	}

	public void setWorkingBean(Party bean) {
		model.setValueObject(bean);

	}
}
